# -*- encoding: utf-8 -*-
"""
PyCharm stage
2022年09月10日
by littlefean
"""
from typing import *
from div import Div


class Stage:
    def __init__(self):
        self.fileName = "xxxx.html"
        self.backgroundColor = "white"
        self.divList: List["Div"] = []
        ...

    def addDiv(self, div: Div):
        """
        将一个div对象加入到舞台中，
        这里面会有比较复杂的变化：
        div所表示的标签会被增加到html中，
        div所绑定的动画会添加到css中
        div的style也会添加到css中
        :param div:
        :return:
        """
        self.divList.append(div)

    def save(self):
        html = ""
        css = ""
        for div in self.divList:
            html += div.bodyStr()
            css += div.animationStr()
            css += div.cssStr()

        with open(self.fileName, "w", encoding="utf-8") as f:
            content = f"""
            <!doctype html>
            <html lang="zh-CN">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport"
                      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
                <meta http-equiv="X-UA-Compatible" content="ie=edge">
                <title>Document</title>
                <style>
                * {{
                    margin: 0;
                    padding: 0;
                    box-sizing: border-box;
                }}
                body {{
                    background-color: {self.backgroundColor}
                }}
                main {{
                    width: 100%;
                    height: 100vh;
                    position: relative;
                    overflow:hidden;
                }}
                {css}
                </style>
            </head>
            <body>
            <main>
                {html}
            </main>
            </body>
            <script>
            </script>
            </html>
            """
            f.write(content)


def main():
    return None


if __name__ == "__main__":
    main()
